package com.yang.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yang.domain.UserCarDetails;
import com.yang.service.UserCarDetailsService;
import com.yang.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 用户车辆明细Controller
 *
 * @author 不是菜鸡爱编程
 * @date 2024-02-18
 */
@RestController
@RequestMapping("/userCarDetails")
@Api(tags = "用户车辆明细", value = "用户车辆明细Controller")
public class UserCarDetailsController {
    @Autowired
    private UserCarDetailsService userCarDetailsService;

    /**
     * 查询用户车辆明细列表
     */
    @ApiOperation("查询用户车辆明细列表")
    @GetMapping("/list")
    public IPage<UserCarDetails> list(UserCarDetails userCarDetails) {
        //startPage();
        //List<UserCarDetails> list = userCarDetailsService.selectUserCarDetailsList(userCarDetails);
        //return getDataTable(list);
        return null;
    }

    /**
     * 获取用户车辆明细详细信息
     */
    @ApiOperation("获取用户车辆明细详细信息")
    @GetMapping(value = "/{userId}")
    public R getInfo(@PathVariable("userId") Long userId) {
        return R.ok().setData(userCarDetailsService.list(new LambdaQueryWrapper<UserCarDetails>()
                .eq(UserCarDetails::getUserId,userId)));
    }

    /**
     * 新增用户车辆明细
     */
    @ApiOperation("新增用户车辆明细")
    @PostMapping
    public R add(@RequestBody UserCarDetails userCarDetails) {
        return R.ok().setData(userCarDetailsService.save(userCarDetails));
    }

    /**
     * 修改用户车辆明细
     */
    @ApiOperation("修改用户车辆明细")
    @PutMapping
    public R edit(@RequestBody UserCarDetails userCarDetails) {
        return R.ok().setData(userCarDetailsService.update(userCarDetails,new LambdaQueryWrapper<UserCarDetails>()
                .eq(UserCarDetails::getUserId,userCarDetails.getUserId())
                .eq(UserCarDetails::getCarCard,userCarDetails.getCarCard())));
    }

    /**
     * 删除用户车辆明细
     */
    @ApiOperation("删除用户车辆明细")
    @DeleteMapping("/{userIds}")
    public R remove(@PathVariable Long[] userIds) {
        return R.ok().setData(userCarDetailsService.removeByIds(Arrays.asList(userIds)));
    }
}
